import store from '@/common/store'
import base from "@/config/baseUrl";
import api from '@/common/request/index'

//檢查小程序更新
function appletsLogin(httpData){
   api('user.appletslogin', {
   	httpData:httpData,
   }).then(res => {
   		if (res.code==200){
   				store.commit('USER_INFO',res.data);
   				store.commit('TOKEN_INFO',res.data.member_token);
   				uni.setStorageSync("fromLogin", ""); //要跳转到的页面
   				store.dispatch('setTokenAndBack',res.data.member_token);
   			let bussiness = {
   				bid:res.data.bid,
   			};
   			store.commit("setbasebusinessID",bussiness);
   			store.commit('setLoginPopupShow', false);
   			uni.showToast({title: "登录成功"});
   		}else{
   			uni.showToast({title: "登录失败"});
   		}
   }).catch((e)=>{
        console.log(e);
   });
}

function getMiniMobi(httpData){
	api('user.getminimobi', {httpData:httpData}).then((res) => {
		console.log(res)
   		if (res.code==200){
   				store.commit('USER_INFO',res.data);
   				store.commit('TOKEN_INFO',res.data.member_token);
   				uni.setStorageSync("fromLogin", ""); //要跳转到的页面
   				store.dispatch('setTokenAndBack',res.data.member_token);
   			let bussiness = {
   				bid:res.data.bid,
   			};
   			store.commit("setbasebusinessID",bussiness);
   			store.commit('setLoginPopupShow', false);
   			uni.showToast({title: "登录成功"});
   		}else{
   			uni.showToast({title: "登录失败"});
   		}
	}).catch((e) => {});
}

export {
    appletsLogin,    //登陆
	getMiniMobi
}